package com.example.mywechatstickers;

import java.io.File;
import java.util.ArrayList;

import android.os.Environment;

/**
 * 
 * @author 
 *
 */
public class FileUitly {
    private static String SD_PATH;
    private final static String WECHAT_PATH = "/tencent/MicroMsg";
    private final static String WECHAT_STICKERS_PATH  = "emoji";
    //微信路径：/storage/emulated/0/tencent/MicroMsg/
    //微信表情路径：/storage/emulated/0/tencent/MicroMsg/c4c1cfe8b17582d0cb85a5207e74f2c4/emoji
    //微信表情路径：/storage/emulated/0/tencent/MicroMsg/c4c1cfe8b17582d0cb85a5207e74f2c4/emoji

    /**
     * 获取SD卡路径
     */
    private static void getSD_PATH() {
        File sdDir = Environment.getExternalStorageDirectory();//获取跟目录 
        SD_PATH = sdDir.toString();
        System.out.println("SD_PATH:" + SD_PATH);
    }
    
    /**
     * 获取微信路径
     * @return
     */
    private static String getWechatPath() {
        StringBuilder sb = new StringBuilder();
        getSD_PATH();
        sb.append(SD_PATH).append(WECHAT_PATH);
        System.out.println("微信路径：" + sb.toString());
        return sb.toString();
    }
    
    /**
     * 获取微信表情路径
     * @return
     */
    private static String getWechatStickersPath() {
        String WeChatPathStr = getWechatPath();
        System.out.println("微信路径：" + WeChatPathStr);
        String wechatStickersPath = getEmoj(WeChatPathStr);
        System.out.println("微信表情路径：" + wechatStickersPath);
        return wechatStickersPath;
    }

    /**
     * 通过微信路径遍历文件夹，找到微信表情路径
     * @param file
     * @return
     */
    private static String getEmoj(String WeChatPathStr) {
        File file = new File(WeChatPathStr);
        String wechatStickersPath = null;
        System.out.println("file.getAbsolutePath()" + file.getAbsolutePath());
        a:for (File f1:file.listFiles()) {
            if(f1.isDirectory()){
                for (File f2:f1.listFiles()) {
                    //System.out.println("f2 AbsolutePath:" + f2.getAbsolutePath());
                    System.out.println("f2 Name:" + f2.getName());
                    if(f2.isDirectory() && f2.getName().equals(WECHAT_STICKERS_PATH)){
                        wechatStickersPath = f2.getAbsolutePath();
                        System.out.println("wechatStickersPath:" + wechatStickersPath);
                        break a;
                    }
                }
            }
        }
        return wechatStickersPath;
    }
    
    /**
     * 返回微信表情列表
     * @return
     */
    public static ArrayList<?> getWeChatStickers(){
        String wechatStickersPath = getWechatStickersPath();
        System.out.println("getWeChatStickers ----- wechatStickersPath:" + wechatStickersPath);
        ArrayList<?> arrayList = new ArrayList<>();
        return arrayList;
    }
}
